package com.limingru.newbee.util;

import org.apache.commons.lang.StringUtils;

public class ResultGenerator {
    private static String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";
    private static String DEFAULT_FAIL_MESSAGE = "FAIL";
    private static int DEFAULT_SUCCESS_CODE = 200;
    private static int DEFAULT_FAIL_CODE = 500;

    public static Result generateSuccessResult() {
        Result result = new Result();
        result.setResultCode(DEFAULT_SUCCESS_CODE);
        result.setMessage(DEFAULT_SUCCESS_MESSAGE);
        return result;
    }

    public static Result generateSuccessResult(String message) {
        Result result = new Result();
        result.setResultCode(DEFAULT_SUCCESS_CODE);
        result.setMessage(message);
        return result;
    }

    public static Result generateSuccessResult(Object data) {
        Result result = new Result();
        result.setResultCode(DEFAULT_SUCCESS_CODE);
        result.setMessage(DEFAULT_SUCCESS_MESSAGE);
        result.setData(data);
        return result;
    }

    public static Result generateFailResult(String message) {
        Result result = new Result();
        result.setResultCode(DEFAULT_FAIL_CODE);
        if (StringUtils.isEmpty(message)) {
            result.setMessage(DEFAULT_FAIL_MESSAGE);
        }
        result.setMessage(message);
        return result;
    }
}
